/* This dofile generates kernel density plot of normal and asylum opening and converting time */



import excel "normal_school_allschool.xlsx", sheet("Sheet1") firstrow clear

keep State   cnty_fips institution_initialname Year_open Year_regionalcollege Year_regionaluniversity


tempfile normal
save `normal' 


import excel "census_institution_1923.xlsx", sheet("Sheet1") firstrow clear
keep State cnty_fips institution opening_yr open_after1830 asylum_county_only  year_closed

tempfile asylum
save `asylum'


use `normal' ,clear

append using  `asylum'


*drop asylum opened before 1830
drop if open_after1830 == 0

rename Year_open openyr_normal
rename opening_yr openyr_asylum 
rename year_closed closeyr_aslyum

destring Year_regionalcollege,replace 
destring Year_regionaluniversity,replace 

tw(kdensity  openyr_normal,bwidth(5) lcolor(orange) ) (kdensity  openyr_asylum, bwidth(5) lcolor(ebblue) lpattern(dash)) ///
(kdensity  Year_regionalcollege,bwidth(5) lcolor(red))(kdensity  Year_regionaluniversity,bwidth(5) lcolor(navy ) ) , xlabel(1840(20)2000) ///
ytitle("Kernel Desnsity",size(vlarge)) xtitle("") legend(off) graphregion(fcolor(white)) text(0.002 1879 "Normal school""opening year", color(orange)) ///
text(0.02 1861 "Asylum""opening year", color(ebblue)) text(0.036 1933 "Convert to""regional college ", color(red)) ///
text(0.026 2002 "Convert to regional""university ", color(navy )) ///
xlabel(1840(20)2020)
graph export "fig1a.pdf", replace 
//graph export "fig1a.png", as(png) replace 
 